
import io.qt.core.Qt
import io.qt.gui.QMouseEvent
import io.qt.widgets.QSlider
import io.qt.widgets.QWidget


class MySlider (parent:QWidget): QSlider(parent) {

    // defining signals in kotlin
    val clickedPos: Signal0 = Signal0()

    // defining slots

    override fun mousePressEvent(ev: QMouseEvent?) {
        super.mousePressEvent(ev)
        if (orientation() == Qt.Orientation.Horizontal) {
            //获取当前点击位置
            val currentX = ev?.pos()?.x()

            val a = 2 * 2
            //获取当前点击的位置占整个Slider的百分比
            val per = (currentX?.toDouble() ?: 0.0) / this.width

            //利用算得的百分比得到具体数字
            this.value = (per * (this.maximum - this.minimum) + this.minimum).toInt()
        } else {
            //获取当前点击位置
            val currentY = ev?.pos()?.y()

            //获取当前点击的位置占整个Slider的百分比
            val per = (currentY?.toDouble() ?: 0.0) / this.height()
            //利用算得的百分比得到具体数字
            this.value = this.maximum - (per * (this.maximum - this.minimum) + this.minimum).toInt()
        }
//    qDebug()<<"value"<<value<<","<<ev->pos().x()<<ev->pos().y();

        //滑动条移动事件等事件也用到了mousePressEvent,加这句话是为了不对其产生影响，是的Slider能正常相应其他鼠标事件
//            QSlider::mousePressEvent(ev);
        this.clickedPos.emit()

    }
}